Repository navigation
Conversation
Freax13
left a comment
There was a problem hiding this comment.
Thank you for your contribution!
| Page::range(start, end).into_iter().next(); | ||
| } | ||
|
|
||
| // TODO: This probably shouldn't panic, but we can't fix this without a breaking change. |
There was a problem hiding this comment.
Please add this behavior change as a breaking change to the release notes.
|
|
||
| #[test] | ||
| #[should_panic = "attempt to add with overflow or resulted in non-canonical virtual address"] | ||
| fn test_page_range_next_jumping_gap_panics() { |
| assert_eq!( | ||
| Page::range_inclusive(start, end).into_iter().next(), | ||
| Some(start) | ||
| ); |
There was a problem hiding this comment.
We should add similar asserts to the remaining tests that formerly panicked.
| // FIXME: Move this into the `Step` impl, once `Step` is stabilized. | ||
| pub(crate) fn backward_checked_impl(start: Self, count: usize) -> Option<Self> { | ||
| let count = u64::try_from(count).ok()?.checked_mul(S::SIZE)?; | ||
| let start_address = VirtAddr::backward_checked_u64(start.start_address, count)?; | ||
| Some(Self { | ||
| start_address, | ||
| size: PhantomData, | ||
| }) | ||
| } |
There was a problem hiding this comment.
Let's replace the implementation of backward_checked for Page's Step with a call to this function.
| // If the start of the inclusive range is 0, decrementing end until | ||
| // it is smaller than the start will cause an integer underflow. | ||
| // So instead, in that case we increment start rather than decrementing end. | ||
| if self.0.end.start_address().as_u64() != 0 { | ||
| self.0.end -= 1; | ||
| self.0.end = Page::backward_checked_impl(self.0.end, 1)?; | ||
| } else { | ||
| self.0.start += 1; | ||
| self.0.start = Page::forward_checked_impl(self.0.start, 1)?; | ||
| } |
There was a problem hiding this comment.
Let's do this:
// If the start of the inclusive range is 0, decrementing end until
// it is smaller than the start will cause an integer underflow.
// In that case we increment start rather than decrementing end.
if let Some(end) = Page::backward_checked_impl(self.0.end, 1) {
self.0.end = end;
} else {
self.0.start = self.0.start + 1;
}| assert_eq!( | ||
| Page::range_inclusive(start, end).into_iter().next(), | ||
| Some(start) | ||
| ); | ||
| assert_eq!( | ||
| Page::range_inclusive(start, end).into_iter().next(), | ||
| Some(start) | ||
| ); |
There was a problem hiding this comment.
There's a small issue in the original code: We called Page::range_inclusive(start, end).into_iter().next(); twice with the same inputs. We don't need to do this twice.
15f1675 to
fd0d920
Compare
Note that this does not add a checked version for subtracting two addresses yet.
Note that this changes the panic behavior, since `rhs * S::SIZE` did not panic before without overflow checks. Note that this does not add a checked version for subtracting two pages or frames yet.
fd0d920 to
d9c073c
Compare
|
Thanks for the review! All comments should be addressed. :) |
d9c073c to
62ace8a
Compare
I recently discovered that this range panics during iteration, even though it does not even cross the address space gap:
We could use #616 to fix that, similar to #617. I believe it makes more sense to jump the gap, as proposed in #589 and already done via the unstable
Steptrait.